package com.zf.wms.nservice.controller;

import com.zf.wms.nservice.client.PurviewClient;
import com.zf.wms.nservice.utils.ResultMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author：sl
 * Date：2019-11-05 10:49
 * Description：<描述>
 */
@Api(tags = "权限管理")
@RestController
@RequestMapping(value = "/purview")
public class PurviewManageController {


    @Autowired
    private PurviewClient purviewClient;

    /**
     * 查询出所有权限，供管理员配置角色的权限
     * @return
     */
    @RequestMapping(value = "/allList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("查询所有权限")
    public ResultMap getAllList() {

        ResultMap allPurviewList = purviewClient.getAllPurviewList();
        return allPurviewList;
    }


    /**
     * 配置权限，将给角色（roleId）配置的所有权限（ids），保存到数据库中
     * @return
     */
    @RequestMapping(value = "/setRolePurview", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("设置角色权限")
    public ResultMap setRolePurview(@RequestParam(value = "roleId")Integer roleId, @RequestParam(value = "ids")String ids) {
        ResultMap allPurviewList = purviewClient.setRolePurview(roleId,ids);
        return allPurviewList;
    }



}
